package study.sso.jwt.support.jwt;

import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class PayloadV2 extends HashMap<String, Object> {

    /* 编号 */
    public static final String KEY_ID = "jti";
    /* 主题 */
    public static final String KEY_SUBJECT = "sub";
    /* 签发人 */
    public static final String KEY_ISSUER = "iss";


    /* 签发时间 */
    public static final String KEY_ISSUED_AT = "iat";
    //过期时间 */
    public static final String KEY_EXPIRES_AT = "exp";
    /* 生效时间 */
    public static final String KEY_NOT_BEFORE = "nbf";

    @Setter
    @Getter
    private Map<String, String> claims = new HashMap<>();

    public PayloadV2 setId(String jti) {
        put(KEY_ID, jti);
        return this;
    }

    public String getId() {
        return (String) get(KEY_ID);
    }

    public PayloadV2 setSubject(String sub) {
        put(KEY_SUBJECT, sub);
        return this;
    }

    public String getSubject() {
        return (String) get(KEY_SUBJECT);
    }

    public PayloadV2 setIssuer(String iss) {
        put(KEY_ISSUER, iss);
        return this;
    }

    public String getIssuer() {
        return (String) get(KEY_ISSUER);
    }

    public PayloadV2 setIssuedAt(Date iat) {
        put(KEY_ISSUED_AT, iat);
        return this;
    }

    public Date getIssuedAt() {
        return (Date) get(KEY_ISSUED_AT);
    }

    public PayloadV2 setExpiresAt(Date exp) {
        put(KEY_EXPIRES_AT, exp);
        return this;
    }

    public Date getExpiresAt() {
        return (Date) get(KEY_EXPIRES_AT);
    }

    public PayloadV2 setNotBefore(Date nbf) {
        put(KEY_NOT_BEFORE, nbf);
        return this;
    }

    public Date getNotBefore() {
        return (Date) get(KEY_NOT_BEFORE);
    }

    public static void main(String[] args) {
        PayloadV2 payload = new PayloadV2();
    }
}
